home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolf3dmacsource.sit / Wolf3DMacSource / SnesMain.c < prev    next >
C/C++ Source or Header  |  1994-09-29  |  4KB  |  175 lines

  1. #include "WolfDef.h"
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <setjmp.h>
  5. #include <ctype.h>
  6.  
  7. /**********************************
  8.  
  9.     Prepare the screen for game
  10.  
  11. **********************************/
  12.  
  13. void SetupPlayScreen (void)
  14. {
  15.     SetAPalette(rBlackPal);        /* Force black palette */
  16.     ClearTheScreen(BLACK);        /* Clear the screen to black */
  17.     BlastScreen();
  18.     firstframe = 1;                /* fade in after drawing first frame */
  19.     GameViewSize = NewGameWindow(GameViewSize);
  20. }
  21.  
  22. /**********************************
  23.  
  24.     Display the automap
  25.     
  26. **********************************/
  27.  
  28. void RunAutoMap(void)
  29. {
  30.     Word vx,vy;
  31.     Word Width,Height;
  32.     Word CenterX,CenterY;
  33.     Word oldjoy,newjoy;
  34.     
  35.     MakeSmallFont();                /* Make the tiny font */
  36.     playstate = EX_AUTOMAP;
  37.     vx = viewx>>8;                    /* Get my center x,y */
  38.     vy = viewy>>8;
  39.     Width = (SCREENWIDTH/16);        /* Width of map in tiles */
  40.     Height = (VIEWHEIGHT/16);        /* Height of map in tiles */
  41.     CenterX = Width/2;
  42.     CenterY = Height/2;
  43.     if (vx>=CenterX) {
  44.         vx -= CenterX;
  45.     } else {
  46.         vx = 0;
  47.     }
  48.     if (vy>=CenterY) {
  49.         vy -= CenterY;
  50.     } else {
  51.         vy = 0;
  52.     }
  53.     oldjoy = joystick1;
  54.     do {
  55.         ClearTheScreen(BLACK);
  56.         DrawAutomap(vx,vy);
  57.         do {
  58.             ReadSystemJoystick();
  59.         } while (joystick1==oldjoy);
  60.         oldjoy &= joystick1;
  61.         newjoy = joystick1 ^ oldjoy;
  62.         if (newjoy & (JOYPAD_START|JOYPAD_SELECT|JOYPAD_A|JOYPAD_B|JOYPAD_X|JOYPAD_Y)) {
  63.             playstate = EX_STILLPLAYING;
  64.         } 
  65.         if (newjoy & JOYPAD_UP && vy) {
  66.             --vy;
  67.         }
  68.         if (newjoy & JOYPAD_LFT && vx) {
  69.             --vx;
  70.         }
  71.         if (newjoy & JOYPAD_RGT && vx<(MAPSIZE-1)) {
  72.             ++vx;
  73.         }
  74.         if (newjoy & JOYPAD_DN && vy <(MAPSIZE-1)) {
  75.             ++vy;
  76.         }
  77.     } while (playstate==EX_AUTOMAP);
  78.  
  79.     playstate = EX_STILLPLAYING;
  80. /* let the player scroll around until the start button is pressed again */
  81.     KillSmallFont();            /* Release the tiny font */
  82.     RedrawStatusBar();
  83.     ReadSystemJoystick();
  84.     mousex = 0;
  85.     mousey = 0;
  86.     mouseturn = 0;
  87. }
  88.  
  89. /**********************************
  90.  
  91.     Begin a new game
  92.     
  93. **********************************/
  94.  
  95. void StartGame(void)
  96. {    
  97.     if (playstate!=EX_LOADGAME) {    /* Variables already preset */
  98.         NewGame();                /* init basic game stuff */
  99.     }
  100.     SetupPlayScreen();
  101.     GameLoop();            /* Play the game */
  102.     StopSong();            /* Make SURE music is off */
  103. }
  104.  
  105. /**********************************
  106.  
  107.     Show the game logo 
  108.  
  109. **********************************/
  110.  
  111. Boolean TitleScreen (void)
  112. {
  113.     Word RetVal;        /* Value to return */
  114.     LongWord PackLen;
  115.     LongWord *PackPtr;
  116.     Byte *ShapePtr;
  117.  
  118.     playstate = EX_LIMBO;    /* Game is not in progress */
  119.     NewGameWindow(1);    /* Set to 512 mode */
  120.     FadeToBlack();        /* Fade out the video */
  121.     PackPtr = LoadAResource(rTitlePic);
  122.     PackLen = PackPtr[0];
  123.     ShapePtr = (Byte *)AllocSomeMem(PackLen);
  124.     DLZSS(ShapePtr,(Byte *) &PackPtr[1],PackLen);
  125.     DrawShape(0,0,ShapePtr);
  126.     ReleaseAResource(rTitlePic);
  127.     FreeSomeMem(ShapePtr);
  128.     BlastScreen();
  129.     StartSong(SongListPtr[0]);
  130.     FadeTo(rTitlePal);    /* Fade in the picture */
  131.     BlastScreen();
  132.     RetVal = WaitTicksEvent(0);        /* Wait for event */
  133.     playstate = EX_COMPLETED;
  134.     return TRUE;                /* Return True if canceled */
  135. }
  136.  
  137. /**********************************
  138.  
  139.     Main entry point for the game (Called after InitTools)
  140.  
  141. **********************************/
  142.  
  143. jmp_buf ResetJmp;
  144. Boolean JumpOK;
  145. extern Word NumberIndex;
  146.  
  147. void main(void)
  148. {
  149.     InitTools();        /* Init the system environment */
  150.     WaitTick();            /* Wait for a system tick to go by */
  151.     playstate = (exit_t)setjmp(ResetJmp);    
  152.     NumberIndex = 36;    /* Force the score to redraw properly */
  153.     IntermissionHack = FALSE;
  154.     if (playstate) {
  155.         goto DoGame;    /* Begin a new game or saved game */
  156.     }
  157.     JumpOK = TRUE;        /* Jump vector is VALID */
  158.     FlushKeys();        /* Allow a system event */
  159.     Intro();            /* Do the game intro */
  160.     for (;;) {
  161.         if (TitleScreen()) {        /* Show the game logo */
  162.             StartSong(SongListPtr[0]);
  163.             ClearTheScreen(BLACK);    /* Blank out the title page */
  164.             BlastScreen();
  165.             SetAPalette(rBlackPal);
  166.             if (ChooseGameDiff()) {    /* Choose your difficulty */
  167.                 playstate = EX_NEWGAME;    /* Start a new game */
  168. DoGame:
  169.                 FadeToBlack();        /* Fade the screen */
  170.                 StartGame();        /* Play the game */
  171.             }
  172.         }
  173.     }
  174. }
  175.